﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MinhUtils;
using System.Text.RegularExpressions;
using MangaGrr.MgrEventArgs;

namespace MangaGrr.DomainModel
{
    class MangaChapter : IComparable
    {
        public string Name { get; set; }

        /// <summary>
        /// Chapter's volume and number
        /// </summary>
        public string OrderInfo { get; set; }
        public int TotalPage { get; set; }

        /// <summary>
        /// Chapter's URL, and may also be the first Page's URL
        /// </summary>
        public string URL { get; set; }
        public Manga Manga { get; set; }

        /// <summary>
        /// For displaying purpose
        /// </summary>
        public string DisplayName
        {
            get
            {
                return OrderInfo + " " + Name;
            }
        }

        #region IComparable Members

        public int CompareTo(object obj)
        {
            try
            {
                MangaChapter chapter = (MangaChapter)obj;

                if (this.URL == chapter.URL)
                    return 0; //URL is identical
                else
                {
                    int relativeValue = this.Manga.Name.CompareTo(chapter.Manga.Name);
                    if (relativeValue != 0) //compare manga name
                    {
                        return relativeValue;
                    }
                    else if ((relativeValue = this.OrderInfo.CompareTo(chapter.OrderInfo)) != 0) //compare chapter number
                    {
                        return relativeValue;
                    }
                    else //compare chapter name
                    {
                        return this.Name.CompareTo(chapter.Name);
                    }
                }
            }
            catch
            {

            }

            return 0; //equal
        }

        #endregion

        
    }
}
